class Api::V1::ShopCategoriesController < Api::V1::BaseController
  skip_before_action :authenticate_request!, only: [:index, :clearance]

  def index
    params[:parent_id] ||= 0
    if params[:parent_id].blank? || params[:parent_id] == 0
      @shop_categories = ShopCategory.where(published: true).where("parent_id = ? OR parent_id IS NULL", params[:parent_id]).order("sort ASC")
    else
      @shop_categories = ShopCategory.where(published: true).where(parent_id: params[:parent_id]).order("sort ASC")
    end
  end

  def clearance
    @shop_categories = ShopCategory.where(published: true, level: 3, clearance: true).order("sort ASC")
  end
  
end
